import { createStore } from 'vuex';
import { ROLE_CODES } from '@/utils/storage';
export default createStore({
  state: {
    activeMenuIndex: null,
    userInfo: {
      id: null,
      username: null,
      role: null,
      areaId: null, // 所属片区ID
    },
  },
  getters: {
    getUserRole: (state) => {
      const storeRole = state.userInfo.role;
      return storeRole && ROLE_CODES.includes(storeRole) ? storeRole : null;
    },
  },
  mutations: {
    setActiveMenuIndex(state, path) {
      state.activeMenuIndex = path;
    },
    setUserInfo(state, userInfo) {
      state.userInfo = userInfo;
    },
    cleanUserInfo(state) {
      Object.keys(state.userInfo).map((key) => {
        state.userInfo[key] = null;
      });
    },
  },
  actions: {},
  modules: {},
});
